// 导入multer模块;
const multer = require("multer");
// 导入path模块;
const path = require("path");
const storage = multer.diskStorage({
  // 指定导入文件存储的位置
  destination(req, file, cb) {
    cb(null, path.join(__dirname, "../../dist/images/coverImage"));
  },
  // 指定文件名
  filename(req, file, cb) {
    // 随机名称
    cb(
      null,
      Date.now() + Math.random().toString(16) + path.extname(file.originalname)
    );
  },
});

const upload = multer({ storage });

module.exports = upload;
